<!--
 * @Author: delin66
 * @Date: 2025-02-28 20:38:56
 * @LastEditors: delin66
 * @LastEditTime: 2025-03-01 17:21:42
 * @Descripttion: 
-->
<template>
  <div class="container">
    <div class="header">
      <div class="title">园区公告</div>
      <div class="more" @click="more">更多>></div>
    </div>
    <div class="list">
      <div class="column" v-for="(column, index) in noticeColumns" :key="index">
        <div
            class="item"
            v-for="item in column"
            :key="item.id"
            @click="toDynamicDetail(item.id)"
        >
          <div class="line">
            <div class="dot"></div>
            <span class="title ellipsis">
              {{ item.title }}
            </span>
          </div>
          <span class="create-time">{{ item.createTime?.split(' ')[0] ?? '-' }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { getAnnouncementList } from '@/api/park';
import { achievementList } from '@/api/technology-transform';
import { ref, reactive, onMounted, computed } from 'vue';
import { useRouter } from 'vue-router';

const router = useRouter();

const total = ref(0);
const current = ref<number>(1);
// 获取公告列表
const noticeList = ref();

// 跳转详情
function toDynamicDetail(id: string | number) {
  const { href } = router.resolve({
    name: 'noticeDetail',
    query: {
      id,
    },
  });
  window.open(href, '_blank');
}

function more() {
  router.push({
    name: 'noticeAnnouncement',
  });
}
function getNoticeList() {
  const query = {
    type: 0,
    current: current.value,
    status: 1,
  };
  getAnnouncementList(query).then((res: any) => {
    if (res.code === 200) {
      noticeList.value = res.data?.records;
      total.value = res.data?.total;
    }
  });
}

// 分页
function handleCurrentChange(val: number) {
  current.value = val;
  getNoticeList();
}

// 计算两列公告
const noticeColumns = computed(() => {
  if (!noticeList.value) return [];
  const columns = [[], []];
  noticeList.value.forEach((item, index) => {
    columns[index % 2].push(item);
  });
  return columns;
});

onMounted(() => {
  getNoticeList();
});
</script>

<style scoped lang="scss">
.container {
  margin-top: 30px;
  display: flex;
  flex-direction: column;
  width: 100%;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  .header {
    display: flex;
    height: 50px;
    line-height: 50px;
    text-align: center;
    font-size: 25px;
    font-weight: bold;
    color: white;
    background-color: #0370c2;
    clip-path: polygon(0 0, 100% 0, 100% 85%, 96% 85%, 96% 100%, 4% 100%, 4% 85%, 0 85%);
    .title {
      margin: 0 auto;
      font-weight: bolder;
    }
    .more {
      margin-right: 40px;
      font-weight: bold;
      font-size: 16px;
      cursor: pointer;
      z-index: 99;
    }
  }

  .list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    padding: 40px 50px;
    .column {
      .item {
        width: 100%;
        margin: 0 auto;
        padding: 0 2%;
        margin-bottom: 5px;
        display: flex;
        justify-content: space-between;
        border-bottom: 1px solid rgba(0, 0, 0, 0.5);
        .line {
          width: 90%;
          display: flex;
          align-items: center;
        }
        .dot {
          width: 10px;
          height: 10px;
          border-radius: 50%;
          background-color: #338ccb;
        }
        .title {
          margin-left: 10px;
          max-width: 80%;
          font-size: 16px;
          text-overflow: ellipsis;
          &:hover {
            cursor: pointer;
            color: #338ccb;
          }
        }
        .create-time {
          text-wrap: nowrap;
        }
      }
    }
  }
}
</style>